/*-----------加载工作站--------------*/

/*-----------加载部门树--------------*/
function loadingTree() {
    $.ajax({
        url: "/index/deptTrees",
        method: 'POST',
        async: false,
        success: function (res) {
            if (res.code == 0) {
                var ztree = $.fn.zTree.init($("#treeDemo"), setting, res.data);
                parent.zNodes_ = res.data;//传给子页面
                return ztree;
            } else {
                layer.msg(res.msg, {icon: 5, anim: 6, time: 2000});
            }
        },
        error: function (res) {
            layer.msg("加载结算部门失败，请稍后再试！", {icon: 5, anim: 6, time: 2000});
        }
    });
}

function loadingData(index, url, id, msg, value) {
    $.ajax({
        url: url,
        type: "GET",
        data: {},
        async: false,
        success: function (data) {
            if (data.code == 0) {
                if (data.data.length === 0) {
                    return;
                }
                for (var i in data.data) {
                    //第一个值为station的id即工作站的id
                    //第二个值为应用的applicationCode
                    $(id).append("<option value='" + data.data[i].id + ',' + data.data[i].applicationCode + "'>" + data.data[i].name + "</option>");
                }
                var appCode = data.data[0].applicationCode;
                if(appCode==10101){
                    $("#consumeMch").css("display","block");
                }
                //水控应用时显示物理地址
                if(appCode==10102){
                    $("#dvInfoStatus").css("padding-left","13px");
                    $("#macDiv").css("display","block");
                }else{
                    $("#dvInfoStatus").css("padding-left","0px");
                }
                loadingDevType(index, "/dev/devInfo/devTypeList", "#devType", "无设备类型信息，无法新增",data.data[0].applicationCode );
                loadingParmGroup(index, "/dev/devInfo/getParmGroupList", "#parmGroup", "无参数组信息，无法新增", data.data[0].applicationCode);
                layui.form.render("select");
            }
        },
        error: function () {
            parent.layer.msg('系统异常，请稍后重试！', {icon: 5, anim: 6, time: 3000});
        }
    });

}

function loadingDevType(index, url, id, msg, value) {
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        data: {applicationCode: value},
        success: function (data) {
            if (data.code == 0) {
                if (data.data.length === 0) {
                    return;
                }
                for (var i in data.data) {
                    $(id).append("<option value='" + data.data[i].id + "'>" + data.data[i].name + "</option>");
                }
                layui.form.render("select");

            }
        },
        error: function () {
            parent.layer.msg('系统异常，请稍后重试！', {icon: 5, anim: 6, time: 3000});
        }
    });

}
function loadingParmGroup(index, url, id, msg, value) {
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        data: { applicationCode: value},
        success: function (data) {
            if (data.code == 0) {
                if (data.data.length === 0) {
                    return;
                }
                for (var i in data.data) {
                    $(id).append("<option value='" + data.data[i].id+ "'>" + data.data[i].name + "</option>");
                }
                layui.form.render("select");

            }
        },
        error: function () {
            parent.layer.msg('系统异常，请稍后重试！', {icon: 5, anim: 6, time: 3000});
        }
    });

}

function loadingAcc(index, url, id, msg, value) {
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        success: function (data) {
            if (data.code == 0) {
                if (data.data.length === 0) {
                    return;
                }
                for (var i in data.data) {
                    $(id).append("<option value='" + data.data[i].accCode +',' +data.data[i].accDes+"'>" + data.data[i].accDes + "</option>");
                }
                layui.form.render("select");
            }
        },
        error: function () {
            parent.layer.msg('系统异常，请稍后重试！', {icon: 5, anim: 6, time: 3000});
        }
    });

}
function loadingfk(index, url, id, msg, value) {
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        success: function (data) {
            if (data.code == 0) {
                if (data.data.length === 0) {
                    return;
                }
                for (var i in data.data) {
                    $(id).append("<option value='" + data.data[i].id +"'>" + data.data[i].name + "</option>");
                }
                layui.form.render("select");
            }
        },
        error: function () {
            parent.layer.msg('系统异常，请稍后重试！', {icon: 5, anim: 6, time: 3000});
        }
    });

}


/*****************参数校验公共方法区域start ****************/

//是否为汉字
function isChinese(param){
    var reg = /^[\u4E00-\u9FA5]+$/;
    return reg.test(param);
}

//是否为为数字
function isNumber(param){
    var reg = /^[0-9]*$/;
    return reg.test(param);
}

//ip地址+端口校验
function isIPAddress(param){
    var  reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/
    return reg.test(param);
}

/*****************参数校验公共方法区域end****************/


/**************************************时间格式化处理start************************************/
function dateFtt(fmt,date){
    var o = {
        "M+" : date.getMonth()+1,                 //月份
        "d+" : date.getDate(),                    //日
        "h+" : date.getHours(),                   //小时
        "m+" : date.getMinutes(),                 //分
        "s+" : date.getSeconds(),                 //秒
        "q+" : Math.floor((date.getMonth()+3)/3), //季度
        "S"  : date.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt))
        fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
        if(new RegExp("("+ k +")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    return fmt;
}
//创建时间格式化显示
function crtTimeFtt(){
    return dateFtt("yyyy-MM-dd hh:mm:ss",new Date());
}
//格式化日期
function fmtDate(date){
    return dateFtt("yyyy-MM-dd",date);
}

/**************************************时间格式化处理end************************************/